#pragma once
#include <unistd.h>
#include <fcntl.h>
#include "log.hpp"
#include <string.h>

class Util
{
public:
    static bool setNonBlock(int fd)
    {
        int fl = fcntl(fd, F_GETFL);
        if (fl < 0)
        {
            logMessage(ERROR, "setNonBlock fcntl F_GETFL error %d: %s",fd ,strerror(errno));
            return false;
        }
        int ret = fcntl(fd, F_SETFL, fl | O_NONBLOCK);
        if (ret < 0)
        {
            logMessage(ERROR, "setNonBlock fcntl F_SETFL error %d: %s",fd ,strerror(errno));
            return false;
        }
        return true;
    }
};